package com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.handler.impl;

import java.util.Objects;

import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosAcceptStaffDTO;
import com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.BcmcPosContext;
import com.ztesoft.bss.common.bo.PostInfo;
import com.ztesoft.bss.common.bo.UserInfo;
import com.ztesoft.bss.common.util.ContextUtil;

/**
 * <Description> <br>
 * 组装受理员工节点信息
 * 
 * @author XXZ<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2020年12月15日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.handler.impl <br>
 */
@Service
public class BcmcPosAcceptStaffHandler extends AbstractBcmcPosHandler {

    @Override
    public void doHandle(BcmcPosContext context) {
        if (Objects.isNull(context.getPosDto().getAccept())) {
            UserInfo userInfo = ContextUtil.getLoginInfo().getUserInfo();
            PostInfo postInfo = ContextUtil.getLoginInfo().getPostInfos().get(0);
            KitePosAcceptStaffDTO accept = new KitePosAcceptStaffDTO();
            if (Objects.nonNull(userInfo)) {
                if (MapUtils.isNotEmpty(userInfo.getExtParams())) {
                    // 设置政企工号
                    accept.setStaffId(KiteMapUtils.getString(userInfo.getExtParams(), "accountId"));
                    accept.setCode(KiteMapUtils.getString(userInfo.getExtParams(), "account"));
                }
                // 设置受理员工
                accept.setBssCode(userInfo.getUserCode());
                accept.setName(userInfo.getUserName());

                // 设置省市区
                accept.setProvinceCode(userInfo.getPostProvinceNbr());
                accept.setEparchyCode(userInfo.getPostLanId());
                accept.setDistrictCode(String.valueOf(userInfo.getPostRegionId()));
            }
            if (Objects.nonNull(postInfo)) {
                // 设置部门信息
                accept.setDepartmentId(String.valueOf(postInfo.getPostId()));
                accept.setDepartmentName(postInfo.getPostName());
            }
            context.getPosDto().setAccept(accept);
        }

    }

}
